package task13;


import java.util.Scanner;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/27 10:37
 * @description:界面显示
 */
public class DictionaryDaoplay {
static DictionaryDao dao= (DictionaryDao) new DictionaryDaoHashMap();

  public static void main(String[] args) {
    /*1、欢迎界面
      2、接受用户输入选择
      3、根据用户选择来判断
         1)添加界面
         2)查询界面
         3)退出界面*/
    
    while (true) {
      welcomeFace();

      Scanner scanner1 = new Scanner(System.in);
      int num = scanner1.nextInt();
      switch (num) {
        case 1:
          addFace();
          break;
        case 2:
          queryFace();
          break;
        case 3:
          System.out.println("欢迎下次使用");
          System.exit(0);
          break;
        default:
          System.out.println("输入有误");
          break;
      }

    }
  }

  private static void queryFace() {
    System.out.println("****添加词典界面");
    Scanner scanner=new Scanner(System.in);
    System.out.println("请输入英文：");
    String english=scanner.nextLine();
    String chinese=dao.query(english);
    if(chinese==null){
      System.out.println("我还不够智能，还在继续学习中！");
    }else{
      System.out.println(english+"翻译成中文是："+chinese);
    }
  }

  private static void addFace() {
    System.out.println("****添加词典界面");
    Scanner scanner=new Scanner(System.in);
    System.out.println("请输入英文：");
    String english=scanner.nextLine();
    System.out.println("请输入对应的中文：");
    String chinese=scanner.nextLine();
    MyDictionary dictionary=new MyDictionary(english,chinese);
    dao.add(dictionary);
    System.out.println("添加成功！");


  }

  private static void welcomeFace() {
    System.out.println("--------欢迎界面--------");
    System.out.println("1 添加词典内容");
    System.out.println("2 翻译(英翻中)");
    System.out.println("3 退出");
    System.out.println("请输入你的选择");
  }
}
